package com.zhang;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zhang.domain.User;
import com.zhang.mapper.UserMapper;
import org.apache.ibatis.annotations.Update;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Date;

@SpringBootTest
public class DemoTest1 {

    @Autowired
    private UserMapper userMapper;

    @Test
    public void test1() {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        UpdateWrapper<User> updateWrapper = new UpdateWrapper<>();

    }

    //set、setSql
    @Test
    public void test2() {
        //1.修改内容
        User user = new User();
        user.setUsername("诸葛亮3");

        UpdateWrapper<User> updateWrapper = new UpdateWrapper<>();
        updateWrapper
                .set("password","111")
                .setSql("birthday = '2021-06-12'")
                //2.修改条件
                .eq("id",9);

        //3.进行修改
        userMapper.update(user,updateWrapper);

    }

    //groupby
    @Test
    public void test3() {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .groupBy("password");

        Integer count = userMapper.selectCount(queryWrapper);
        System.out.println(count);


    }



}
